I need to import the Excel files(.xls or .xlsx) into DOORS and i had already tried with .csv & .tsv it works fine but i need to import Excel(.xls/.xlsx) files directly into doors.please can anyone support on this.Thanks in advance. dpsin - Mon Oct 27 09:58:18 EDT 2014 |
Re: Importing the Excel file into doors Here's some code I use anytime I need to import from Excel. I found it somewhere else on these forums and always keep this as a file that I can add to whenever someone wants something imported from Excel.
//Import from an excel file
/*
Enter the filepath for the excel file you wish to import from below
in the string variable "filepath".
Use the following functions to import from an excel file:
To get integer values
getCellValue(objExcelSheet, row, col)
To get strings
getCellString(objExcelSheet, row, col)
Simply replace row and col with integer values for the cell you wish to
access. Cell A1 in excel is row = 1 and col = 1.
Enter your code down in main.
*/
//Enter path of file you wish to import from
string filepath = ""
// Prevent dxl timeout
pragma runLim, 0
// Open a file in Excel
OleAutoObj openExcelFile(string sFileName, bool bVisible)
{
OleAutoObj oleWorkbooks = null
OleAutoObj oleExcel = null
OleAutoArgs autoArgs = create
oleExcel = oleGetAutoObject("Excel.Application")
if (null oleExcel)
{
oleExcel = oleCreateAutoObject("Excel.Application")
if(null oleExcel)
{
errorBox("Unable to open excel application")
}
olePut (oleExcel, "Visible", bVisible)
// Get workbooks and open file
clear autoArgs
oleGet(oleExcel,"Workbooks", oleWorkbooks)
put(autoArgs,"Filename", sFileName)
oleMethod(oleWorkbooks,"Open",autoArgs)
}
delete autoArgs
return oleExcel
}
//Get the worksheets
OleAutoObj excelGetWorksheet(OleAutoObj oleExcel, int iSheetNumber)
{
OleAutoObj objExcelSheet = null
string sSheetNumber = "Sheet" iSheetNumber ""
OleAutoArgs autoArgs = create
put(autoArgs ,sSheetNumber)
oleGet(oleExcel,"WorkSheets",autoArgs ,objExcelSheet)
delete autoArgs
return objExcelSheet
}
int getCellValue(OleAutoObj objExcelSheet, int iRow, int iCol)
{
int iValue = 0
OleAutoObj objCell = null
OleAutoArgs autoArgs = create
put(autoArgs,iRow)
put(autoArgs,iCol)
oleGet(objExcelSheet,"Cells",autoArgs,objCell)
if (!null objCell)
{
// Get the value
oleGet(objCell,"Value",iValue)
}
delete autoArgs
return iValue
}
string getCellString(OleAutoObj objExcelSheet, int iRow, int iCol)
{
string sValue = ""
OleAutoObj objCell = null
OleAutoArgs autoArgs = create
put(autoArgs,iRow)
put(autoArgs,iCol)
oleGet(objExcelSheet,"Cells",autoArgs,objCell)
if (!null objCell)
{
// Get the value
oleGet(objCell,"Value",sValue)
}
delete autoArgs
return sValue
}
//close excel
void excelQuit(OleAutoObj oleExcel)
{
oleMethod(oleExcel, "Quit")
oleCloseAutoObject(oleExcel)
}
/******************************************************************************
* MAIN
*****************************************************************************/
OleAutoObj oleExcel = openExcelFile(filepath, true)
OleAutoObj objExcelSheet = excelGetWorksheet(oleExcel, 1)
|
Re: Importing the Excel file into doors From the below forum i got a code to import the Excel document into doors and this code works fine for both the Excel file format .xls & .xlsx. |
Re: Importing the Excel file into doors randragon42 - Tue Oct 28 17:10:31 EDT 2014 Here's some code I use anytime I need to import from Excel. I found it somewhere else on these forums and always keep this as a file that I can add to whenever someone wants something imported from Excel.
//Import from an excel file
/*
Enter the filepath for the excel file you wish to import from below
in the string variable "filepath".
Use the following functions to import from an excel file:
To get integer values
getCellValue(objExcelSheet, row, col)
To get strings
getCellString(objExcelSheet, row, col)
Simply replace row and col with integer values for the cell you wish to
access. Cell A1 in excel is row = 1 and col = 1.
Enter your code down in main.
*/
//Enter path of file you wish to import from
string filepath = ""
// Prevent dxl timeout
pragma runLim, 0
// Open a file in Excel
OleAutoObj openExcelFile(string sFileName, bool bVisible)
{
OleAutoObj oleWorkbooks = null
OleAutoObj oleExcel = null
OleAutoArgs autoArgs = create
oleExcel = oleGetAutoObject("Excel.Application")
if (null oleExcel)
{
oleExcel = oleCreateAutoObject("Excel.Application")
if(null oleExcel)
{
errorBox("Unable to open excel application")
}
olePut (oleExcel, "Visible", bVisible)
// Get workbooks and open file
clear autoArgs
oleGet(oleExcel,"Workbooks", oleWorkbooks)
put(autoArgs,"Filename", sFileName)
oleMethod(oleWorkbooks,"Open",autoArgs)
}
delete autoArgs
return oleExcel
}
//Get the worksheets
OleAutoObj excelGetWorksheet(OleAutoObj oleExcel, int iSheetNumber)
{
OleAutoObj objExcelSheet = null
string sSheetNumber = "Sheet" iSheetNumber ""
OleAutoArgs autoArgs = create
put(autoArgs ,sSheetNumber)
oleGet(oleExcel,"WorkSheets",autoArgs ,objExcelSheet)
delete autoArgs
return objExcelSheet
}
int getCellValue(OleAutoObj objExcelSheet, int iRow, int iCol)
{
int iValue = 0
OleAutoObj objCell = null
OleAutoArgs autoArgs = create
put(autoArgs,iRow)
put(autoArgs,iCol)
oleGet(objExcelSheet,"Cells",autoArgs,objCell)
if (!null objCell)
{
// Get the value
oleGet(objCell,"Value",iValue)
}
delete autoArgs
return iValue
}
string getCellString(OleAutoObj objExcelSheet, int iRow, int iCol)
{
string sValue = ""
OleAutoObj objCell = null
OleAutoArgs autoArgs = create
put(autoArgs,iRow)
put(autoArgs,iCol)
oleGet(objExcelSheet,"Cells",autoArgs,objCell)
if (!null objCell)
{
// Get the value
oleGet(objCell,"Value",sValue)
}
delete autoArgs
return sValue
}
//close excel
void excelQuit(OleAutoObj oleExcel)
{
oleMethod(oleExcel, "Quit")
oleCloseAutoObject(oleExcel)
}
/******************************************************************************
* MAIN
*****************************************************************************/
OleAutoObj oleExcel = openExcelFile(filepath, true)
OleAutoObj objExcelSheet = excelGetWorksheet(oleExcel, 1)
Thank you for the reply and From the below forum i got a code to import the Excel document into doors and this code works fine for both the Excel file format .xls & .xlsx. In the code taken from the above forum attributes has to be created first and then only it can import the Excel data but i need to create attribute by reading Excel column headings.Is there any code available to do like that? |
Re: Importing the Excel file into doors try use..C# oledb in excel |